/*
 * Copyright (C) 2015 - present Instructure, Inc.
 *
 * This file is part of Canvas.
 *
 * Canvas is free software: you can redistribute it and/or modify it under
 * the terms of the GNU Affero General Public License as published by the Free
 * Software Foundation, version 3 of the License.
 *
 * Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Affero General Public License along
 * with this program. If not, see <http://www.gnu.org/licenses/>.
 */

// @mixin primary-nav-badge-border($border-color) { box-shadow: 0 0 0 2px $border-color; }


/// These are editable variables from the theme editor.
/// For more info view stylesheets/brandable_variables.json
// ic-brand-global-nav-bgd
// ic-brand-global-nav-ic-icon-svg-fill
// ic-brand-global-nav-menu-item__text-color
// ic-brand-global-nav-avatar-border
// ic-brand-global-nav-menu-item__badge-bgd
// ic-brand-global-nav-menu-item__badge-text
// ic-brand-global-nav-ic-icon-svg-fill--active
// ic-brand-global-nav-logo-bgd

$ic-global-nav-link-hover: rgba(black, 0.2);
$ic-global-nav-link-active:  rgba(black, 0.4);
$ic-masquerade-color: $ic-color-action;
$ic-subnav-panel-bgd: $ic-color-light;
$ic-subnav-tray-bgd: black;
$ic-tooltip-arrow-size: 0.375rem;


.ic-app-header {
  box-sizing: border-box;
  position: fixed;
  top: 0; left: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  width: $ic-header-primary-width - 30;
  z-index: 100;
  background-color: $ic-brand-global-nav-bgd;
}

.ic-app-header__main-navigation {
  box-sizing: border-box;
  flex: 1 0 auto;
}

.ic-app-header__secondary-navigation {
  box-sizing: border-box;
  position: absolute;
  left: 0;
  bottom: 0;
  z-index: 1;
  width: 100%;
}

.ic-app-header__menu-list {
  @include reset-list;
}

.ic-app-header__menu-list-item {
  box-sizing: border-box;

  &.ic-app-header__menu-list-item--active {
    .ic-app-header__menu-list-link {
      background: $ic-color-light;

      body:not(.primary-nav-expanded) & {
        &:hover, &:focus {
          .menu-item__text {
            transition: none;
            transition-delay: 0;
            transform: none;
            opacity: 0;
          }
        }
      }
    }
    .ic-icon-svg {
      fill: $ic-brand-global-nav-ic-icon-svg-fill--active;
    }
    .ic-avatar {
      border-color: $ic-border-light;
      &.ic-avatar--fake-student {
        border-color: $ic-masquerade-color;
      }
    }
    .menu-item-icon-container {
      color: $ic-brand-global-nav-ic-icon-svg-fill--active;
    }
  }
}

.ic-app-header__menu-list-link {
  box-sizing: border-box;
  transition:
    background-color 0.3s,
    padding 0.3s;
  position: relative;
  text-align: center;
  display: block;
  color: $ic-brand-global-nav-menu-item__text-color;

  &:not(.ic-app-header__menu-list-link--nav-toggle) {
    padding: 0.25rem 0;
    @media only screen and (min-height: 400px) {
      padding: 0.4375rem 0;
    }
  }

  &.ic-app-header__menu-list-link--nav-toggle {
    height: 2.5rem;
    perspective: 600px;

    .ic-icon-svg--navtoggle {
      position: absolute;
      left: 50%;
      margin-left: -13px;
      top: 50%;
      margin-top: -10px;
      transition: all 0.4s;
    }
  }

  &:hover, &:focus {
    background-color: $ic-global-nav-link-hover;
    @if $use_high_contrast == false {
      text-decoration: none;
      outline: none;
    }
    .ic-avatar {
      border-color: $ic-brand-global-nav-avatar-border;
      &.ic-avatar--fake-student { border-color: $ic-masquerade-color; }
    }
    .menu-item__text {
      transform: translate3d($ic-tooltip-arrow-size, 0, 0);
      opacity: 1;
    }
  }

  &:active {
    background-color: $ic-global-nav-link-active;
    box-shadow: inset 0 1px 1px rgba(black, 0.3);
  }

  .ic-icon-svg {
    width: 26px;
    display: inline-block;
    vertical-align: middle;
    fill: $ic-brand-global-nav-ic-icon-svg-fill;
  }

  // Need to provide heights for IE11
  .ic-icon-svg--dashboard { height: 30px; }
  .ic-icon-svg--calendar,
  .ic-icon-svg--inbox,
  .ic-icon-svg--apps { height: 28px; }
  .ic-icon-svg--courses { height: 26px; }
  .ic-icon-svg--grades { height: 30px; }
  .ic-icon-svg--arrow-right { width: 24px; height: 24px; }
  .ic-icon-svg--groups { width: 32px; height: 21.6px; }
  .ic-icon-svg--accounts { width: 26px; height: 29px; }
  .ic-icon-svg--login { width: 26px; height: 29px; }
  .ic-icon-svg--lti { width: 26px; height: 29px; }
  .ic-icon-svg--help { height: 26px; }
  .ic-icon-svg--navtoggle { height: 20px; }

  // IE11 height rules for custom help icons
  .svg-icon-lifepreserver,
  .svg-icon-help,
  .svg-icon-information,
  .svg-icon-folder,
  .svg-icon-cog {
    height: 26px;
  }
}

button.ic-app-header__menu-list-link {
  background: transparent;
  border: none;
  width: 100%;
  outline: none;
}

.ic-avatar {
  overflow: hidden;
  border-radius: 100%;
  border: 2px solid $ic-brand-global-nav-avatar-border;
  width: 50px; height: 50px;
  box-sizing: border-box;
  display: inline-block;
  vertical-align: middle;
  &.ic-avatar--fake-student { border-color: $ic-masquerade-color; }
}

.menu-item-icon-container {
  transform: translate3d(0,0,0);
  position: relative;
  z-index: 1;
  width: $ic-sp*4;
  margin: 0 auto;
  color: $ic-brand-global-nav-ic-icon-svg-fill;

  .ic-avatar {
    transform: translate3d(0,0,0);
    width: $ic-sp*2.5;
    height: $ic-sp*2.5;

    body.primary-nav-expanded & {
      width: $ic-sp*3; height: $ic-sp*3;
    }
  }
}

.menu-item__text {
  // set up properties to transition on hover/focus
  transform: translate3d(-100%,0,0);
  opacity: 0;

  pointer-events: none;
  box-sizing: border-box;
  background-color: $ic-brand-global-nav-ic-icon-svg-fill--active;
  position: absolute;
  left: 100%;
  top: 50%;
  padding: 0 $ic-sp;
  line-height: 1.8rem;
  margin-top: -0.9rem;
  @include fontSize($ic-font-size--xsmall);
  border-radius: $ic-border-radius / 2;
  color: $ic-color-light;
  white-space: nowrap;

  // this class is added after a 1s delay because the
  // transitions look weird when the nav is being closed
  body.primary-nav-transitions & {
    transition:
      transform 0.3s cubic-bezier(0.175, 0.885, 0.320, 1.275),
      opacity 0.3s;
    transition-delay: 0.3s;
  }

  &::after {
    right: 100%;
    top: 50%;
    border: solid transparent;
    content: "";
    height: 0;
    width: 0;
    position: absolute;
    pointer-events: none;
    border-color: transparent;
    border-right-color: $ic-brand-global-nav-ic-icon-svg-fill--active;
    border-width: $ic-tooltip-arrow-size;
    margin-top: -($ic-tooltip-arrow-size);
  }
}

.menu-item__badge {
  @include ic-badge-maker;
  transition: all 0.3s ease-out;
  position: absolute;
  top: -0.5em; right: 0;
  background: $ic-brand-global-nav-menu-item__badge-bgd;
  color: $ic-brand-global-nav-menu-item__badge-text;
}

.ic-app-header__logomark-container {
  width: 100%;
  background-color: $ic-brand-global-nav-logo-bgd;
  box-sizing: border-box;
  padding: 0;
}

.ic-app-header__logomark {
  display: block;
  width: 100%;
  overflow: hidden;
  margin: 0 auto;
  background-image: $ic-brand-header-image;
  background-position: 50%;
  background-repeat: no-repeat;
  background-size: contain;
  transition: transform 0.3s;
  height: 75px;

  body.primary-nav-expanded & {
    height: 85px;
  }
}
// set to block to avoid any exta inline spacing at bottom
.ic-app-header__uploaded-logo { display: block; }

// stuff that changes when the nav is expanded
body.primary-nav-expanded {

  .ic-app-header {
    width: $ic-header-primary-width;
    overflow-y: auto;
    -ms-overflow-style: none; // IE11 and below was throwing on scrollbars no matter if needed or not
  }

  .ic-app-header__secondary-navigation {
    position: static;
    left: auto;
    bottom: auto;
    z-index: auto;
    width: auto;
  }

  .ic-app-header__menu-list-item.ic-app-header__menu-list-item--active {
    .menu-item__text {

      @if $use_high_contrast {
        color: $ic-link-color;
      }
      @else {
        color: $ic-brand-global-nav-menu-item__text-color--active;
      }
    }
  }

  .ic-app-header__menu-list-link {
    &:not(.ic-app-header__menu-list-link--nav-toggle) {
      padding: 0.5625rem 0;
    }

    &.ic-app-header__menu-list-link--nav-toggle {
      .ic-icon-svg--navtoggle {
        transform: rotate3d(0, 1, 0, -180deg);
      }
    }

    &:hover, &:focus {
      .menu-item__text {
        transform: none;
      }
    }
  }

  .menu-item__text {
    transition: none;
    position: static;
    left: auto;
    top: auto;
    transform: none;
    opacity: 1;
    text-align: center;
    display: block;
    line-height: 1.4;
    border-radius: 0;
    margin: $ic-sp/4 0 0;
    padding: 0;
    background: transparent;
    color: $ic-brand-global-nav-menu-item__text-color;
    white-space: normal;
    word-wrap: break-word;
    padding-left: 0.25rem;
    padding-right: 0.25rem;

    &::after {
      display: none;
    }
  }
}

// react-tray component styles
.ReactTrayPortal {
  position: relative;
  z-index: 10;
}

.ReactTray__Overlay {
  background: rgba($ic-subnav-tray-bgd, 0.5);
  opacity: 0;
  &.ReactTray__Overlay--after-open {
    transition: opacity 0.4s;
    opacity: 1;
  }
}

.ReactTray__Content {
  box-sizing: border-box;
  transform: translate3d(-100%,0,0);
  background: $ic-color-light;
  padding: $ic-sp*1.5 $ic-sp*2;
  overflow-x: hidden;
  width: $ic-sp*28;
  top: 0; bottom: 0;
  left: $ic-header-primary-width - 30;
  @if $use_high_contrast == false {
    &:focus { outline: none; }
  }
  body.primary-nav-expanded & {
    left: $ic-header-primary-width;
  }
}

.ReactTray__Content--after-open {
  transition: transform 0.2s ease-out;
  transform: translate3d(0,0,0);
}

.ReactTray__Content--before-close {
  transition: all 0.2s ease-in;
  transform: translate3d(-100%,0,0);
  opacity: 0;
}

.ReactTray__layout {
  box-sizing: border-box;
  height: 100%;
  display: flex;
  flex-direction: column;
}


// Nav menu styles

.ic-NavMenu__primary-content {
  flex: 1 0 auto;
}

.ic-NavMenu__secondary-content {
  margin-top: $ic-sp;
}

.ic-NavMenu__link-list {
  @include reset-list;
  @include fontSize($ic-font-size--small);
  .ic-NavMenu-list-item {
    line-height: 1.3;
    margin-bottom: $ic-sp;
    &:last-of-type { margin-bottom: 0; }
    &.ic-NavMenu-list-item--feature-item {
      border-top: 1px solid $ic-border-light;
      padding-top: $ic-sp;
    }
    &.ic-NavMenu-list-item--loading-message {
      text-align: center;
    }
  }

  .ic-NavMenu-list-item__link {
    display: inline-block;
    &:focus {
      @include ic-focus-base;
      //@include ic-focus-variant($color: $ic-link-color), $offset: 2px;
    }
    i[class*=icon-],
    i[class^=icon-] { margin-right: $ic-sp/3; }
  }

}

.ic-NavMenu__header {
  border-bottom: 1px solid $ic-border-light;
  margin-bottom: $ic-sp;

  &:not(.ic-NavMenu__header--is-profile) {
    padding-bottom: $ic-sp;
    display: flex;
    align-items: flex-start;

    .ic-NavMenu__headline {
      flex: 1;
      min-width: 1px;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
    }

  }

  &.ic-NavMenu__header--is-profile {
    text-align: center;
    padding-bottom: $ic-sp*2;

    .ic-avatar {
      border: none;
      background-color: $ic-bg-light-neutral;
      width: 72px; height: 72px;
    }
  }

}

.ic-NavMenu-profile-header-avatar-image {
  min-width: 72px; min-height: 72px;
}

.ic-NavMenu-profile-header-close { text-align: right; }

.ic-NavMenu-profile-header-logout-form {
  margin-top: $ic-sp;
  margin-bottom: 0;
}

.ic-NavMenu__headline {
  @include fontSize(21px);
  box-sizing: border-box;
  margin: 0;
}

.ic-NavMenu-list-item__helper-text {
  color: $ic-hint-text;
  @include fontSize(12px);
  text-transform: uppercase;
  margin-top: $ic-sp/6;

  &.is-help-link {
    text-transform: none;
  }
}


// help dialog/tray styles
.ic-HelpDialog__form-legend {
  display: table;
  font-size: 1em;
  line-height: inherit;
  font-weight: bold;
  margin: 0;
  padding: 0;
  border: 0;
  min-width: 0;
}

.ic-HelpDialog__form-fieldset {
  border: 0;
  padding: 0.01em 0 0 0;
  min-width: 0;
  margin: 0 0 $spacing-width/2 0;
}

.ic-HelpDialog__form-actions {
  display: flex;
  justify-content: flex-end;
}
